(function (w, d){
  var prot = ( (/^((https|chrome-extension):)/i).test(w.location.protocol) ? 'https' : 'http'),
  u = prot + '://share.pluso.ru', uid="1365096170867",
  tags = "getElementsByTagName",
  h = d[tags]("head")[0] || d[tags]("body")[0],
  b = d.documentElement, db = d.body,
  compat = 0/*@cc_on +(d.compatMode=='BackCompat')@*/;


  function js(url, id, callback)
  {
    if (typeof id == "function")
    {
    	callback = id;
    	id = null;
    }

    if (id && d.getElementById(id)) return;

    if (url.charAt(0)=="+") url = u + '/' + url.substring(1);

    s = d.createElement("script");
    s.type = "text/javascript";
    s.charset='UTF-8';
    s.async = true;
    s.src = url;

    if (typeof callback == "function")
    {
      var called = false;
      s.onreadystatechange = function()
      {
        if (this.readyState == "complete" && !called)
        {
          called = true;
          callback();
        }
      };
      s.onload = function()
      {
        if (!called)
        {
        	called = true;
        	callback();
        }
      };
    }

    h.appendChild(s);
  }


  function styled(rules)
  {
    var s = d.createElement('style');
    s.setAttribute("type", "text/css");
    h.appendChild(s);

    if (s.styleSheet) {
        s.styleSheet.cssText = rules;
    } else {
        s.appendChild(d.createTextNode(rules));
    }
  }


  // event position
  function pointed(event)
  {
    return {
             pageX:(typeof event.pageX!='undefined'?event.pageX:(event.clientX + d.body.scrollLeft + b.scrollLeft)),
  	  	     pageY:(typeof event.pageY!='undefined'?event.pageY:(event.clientY + d.body.scrollTop + b.scrollTop))
  	  	   };
  }

  function dimensions()
  {
    return {
             width: w.innerWidth||b.clientWidth||(db && db.clientWidth),
             height:Math.max( db && db.scrollHeight, db && db.offsetHeight, b.clientHeight, b.scrollHeight, b.offsetHeight )
           }
  }

  function numk(num, mini)
  {
     var d=(typeof mini!='undefined'?0:1);
     if (num >= 1000000000) {
        return (num / 1000000000).toFixed(d).replace(/\.0$/, '') + 'G';
     }
     if (num >= 1000000) {
        return (num / 1000000).toFixed(d).replace(/\.0$/, '') + 'M';
     }
     if (num >= 1000) {
        return (num / 1000).toFixed(d).replace(/\.0$/, '') + 'K';
     }
     return num;
  }

  // old browser support
  if(!Array.indexOf){
  	Array.prototype.indexOf = function(obj){
      for(var i=0, l=this.length; i<l; i++){
        if(this[i]==obj){
        	return i;
        }
      }
      return -1;
    }
  }

  if (!Array.prototype.map) {
    Array.prototype.map = function( f ) {
      var result = [];
      for(var i=0,l=this.length; i<l; i++) {
        result.push( f(this[i]) );
      }
      return result;
    };
  };


  var iterate = function(obj, callback)
  {
    for (var key in obj) if (obj.hasOwnProperty(key)) callback(key, obj);
  }

  // get elements by class name
  var elements = (d.querySelectorAll?
  				 function (className, context){return (context || d).querySelectorAll("." + className)}:
 				 function (className, context){
                         if(!className) return [];
                         var e = (context || d)[tags]('*');
                         var list = [];
                         for (var i = 0, length = e.length; i < length; i++) {
                         	var clss = e[i].className.split(' ');
                         	if (clss.indexOf(className)>-1)
                         		list.push(e[i]);
                         }
                         return list;
 					});


  var encode = encodeURIComponent;

  var cloned = function(obj)
  {
    if (typeof obj.length!='undefined') return obj.slice(0);

    var clone = {};
    for(var i in obj) {
        if(typeof(obj[i])=="object")
            clone[i] = cloned(obj[i]);
        else
            clone[i] = obj[i];
    }
    return clone;
  }

  var arrayed = function(obj)
  {
    return Object.prototype.toString.call(obj) === '[object Array]';
  }


  var lang = function(elem, service, title)
  {
   var language = elem.pluso.params.lang;
   if (title)
   {
     return (pluso.lang[language] && pluso.lang[language].titles && pluso.lang[language].titles[service]) || title;
   }
   else
     return (pluso.lang[language] && pluso.lang[language][service])
         || (pluso.lang['ru'] && pluso.lang['ru'][service])
         || service;
  }

  // cross-browser DOM ready handler
  var ready = (function (w, d)
  {
    var inited = false, loaded = false, queue = [], done, old;

    function go()
    {
      if (!inited)
      {
        if (!d.body) return setTimeout(go, 13);

        inited = true;
        if (queue)
        {
          var j, k = 0;
          while ((j = queue[k++])) j.call(null)
          queue = null;
        }
      }
    }

    function check()
    {
      if (loaded) return;
      loaded = true;

      if (d.readyState === "complete") return go();

      if (d.addEventListener)
      {
        d.addEventListener("DOMContentLoaded", done, false);
        w.addEventListener("load", go, false)
      }
      else
      {
        if (d.attachEvent)
        {
          d.attachEvent("onreadystatechange", done);
          w.attachEvent("onload", go);
          var k = false;
          try
          {
            k = w.frameElement == null
          }
          catch (j)
          {}
          if (b.doScroll && k) ie();
        }
        else
        {
         old=w.onload;
         w.onload=function(e)
         {

           old(e);
           go()
         }
        }
      }
    }

    if (d.addEventListener)
    {
      done = function ()
      {
        d.removeEventListener("DOMContentLoaded", done, false);
        go()
      }
    }
    else
    {
      if (d.attachEvent)
      {
        done = function ()
        {
          if (d.readyState === "complete")
          {
            d.detachEvent("onreadystatechange", done);
            go()
          }
        }
      }
    }

    function ie()
    {
      if (inited) return;

      try
      {
        b.doScroll("left")
      }
      catch (j)
      {
        setTimeout(ie, 1);
        return
      }
      go()
    }

    return function (callback)
    {
      check();
      if (inited)
      {
        callback.call(null)
      }
      else
      {
        queue.push(callback)
      }
    }
  })(w, d);



  // begin but don't dublicate
  if (w.pluso && typeof w.pluso.start == "function") return;

  if (!w.pluso) w.pluso = {};

  pluso.cnt=0;
  pluso.uid=uid;


  if(!w.pluso.lang) w.pluso.lang={};

  pluso.lang['ru']= {
    'close':'Закрыть',
    'get':'Получите свои кнопки',
    'share':'Поделитесь с друзьями!',
    'bookmark':'Скопируйте и добавьте эту ссылку в Закладки'
  };

  pluso.lang['ua'] = {
    'close':'Закрити',
    'get':'Отримаєте свої кнопки',
    'share':'Поділитеся з друзями!',
    'bookmark':'Скопіюйте та додайте цю посилання в Закладки'
  };

  pluso.lang['by'] = {
    'close':'Зачыніць',
    'get':'Атрымаеце свае кнопкі',
    'share':'Падзяліцеся з сябрамі!',
    'bookmark':'Скапіюйце і дадайце гэтую спасылку ў Закладкі'
  };

  pluso.lang['en'] = {
    'close':'Close',
    'get':'Get Your Buttons',
    'share':'Share With Friends!',
    'bookmark':'Copy the link and paste to your Bookmarks',

    'titles': {
  	  'vkontakte':'VKontakte',
  	  'odnoklassniki':'Odnoklassniki',
  	  'moimir':'MoiMir@Mail.Ru',
  	  'bobrdobr':'BobrDobr',
  	  'vkrugu':'VKruguDruzei',
  	  'yandex':'ya.ru',
  	  'yazakladki':'Yandex.Bookmarks',
  	  'moikrug':'MoiKrug',
  	  'googlebookmark':'Google Bookmarks',
  	  'yahoo':'Yahoo Bookmarks',
  	  'moemesto':'MoeMesto',
  	  'bookmark':'Add to Favorite',
  	  'email':'Send by E-mail',
  	  'print':'Print'
  	}
  };


  pluso.css=[[["",".pluso"],"position:relative;z-index:1;display:inline-block;padding:0;-webkit-border-radius:22px;-moz-border-radius:22px;border-radius:22px;background:transparent;text-align:left;font-size:0;line-height:0;*display:inline;*zoom:1;"]
,[["0","a:active"]," opacity:.6; "]
,[[32,".pluso-wrap a"],"display:inline-block;vertical-align:inherit;margin:5px 0 0 5px;padding:0;width:40px;height:40px;background:url({i}\/i\/round\/big\/04.png) 0 0 transparent no-repeat;"]
,[[64,".pluso-wrap a"],"display:inline-block;vertical-align:inherit;margin:3px 0 0 3px;padding:0;width:20px;height:20px;background:url({i}\/i\/round\/small\/04.png) 0 0 transparent no-repeat;"]
,[[16,".pluso-wrap a"],"display:inline-block;vertical-align:inherit;margin:3px 0 0 3px;padding:0;width:30px;height:30px;background:url({i}\/i\/round\/medium\/04.png) 0 0 transparent no-repeat;"]
,[["0",".pluso-wrap"],"position:relative;z-index:1;display:inline-block;padding:0 5px 5px 0;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;background:{bb};text-align:left;font-size:0;line-height:0;*display:inline;*zoom:1;"]
,[[64,".pluso-wrap"],"padding:0 3px 3px 0px;"]
,[[66,".pluso-wrap"],"-webkit-border-radius:12px;-moz-border-radius:12px;border-radius:12px;"]
,[[16,".pluso-wrap"],"padding:0 3px 3px 0px;"]
,[[18,".pluso-wrap"],"-webkit-border-radius:12px;-moz-border-radius:12px;border-radius:12px;"]
,[[34,".pluso-wrap"],"-webkit-border-radius:22px;-moz-border-radius:22px;border-radius:22px;"]
,[[544,""],"width:50px;"]
,[[800,""],"width:95px;"]
,[[576,""],"width:26px;"]
,[[528,""],"width:36px;"]
,[[832,""],"width:49px;"]
,[[784,""],"width:69px;"]
,[[32,"a.pluso-more"],"width:40px;height:40px;background:url({i}\/i\/plus.png) 0 -60px no-repeat!important;position:relative;"]
,[[64,"a.pluso-more"],"width:20px;height:20px;background:url({i}\/i\/plus.png) 0 0 no-repeat!important;position:relative;"]
,[[16,"a.pluso-more"],"width:30px;height:30px;background:url({i}\/i\/plus.png) 0 -25px no-repeat!important;position:relative;"]
,[[576,"a.pluso-more"],"margin-bottom:-12px;*left:5px;"]
,[[832,"a.pluso-more"],"margin-left:13px;*left:13px;"]
,[[1216,"a.pluso-more"],"margin-right:-12px;*left:5px;"]
,[[1344,"a.pluso-more"],"margin-right:-12px;top:-12px;*left:auto;"]
,[[528,"a.pluso-more"],"margin-bottom:-12px;*left:5px;"]
,[[784,"a.pluso-more"],"margin-left:18px;*left:18px;"]
,[[1168,"a.pluso-more"],"margin-right:-12px;*left:5px;"]
,[[1296,"a.pluso-more"],"margin-right:-18px;top:-17px;*left:auto;"]
,[[544,"a.pluso-more"],"margin-bottom:-22px;*left:5px;"]
,[[800,"a.pluso-more"],"margin-left:27px;*left:27px;"]
,[[1056,"a.pluso-more"],"margin-right:-22px;*left:5px;"]
,[[1312,"a.pluso-more"],"top:-22px;*left:auto;"]
,[[64,".pluso-counter b"],"position:relative;padding:2px 4px;-webkit-border-radius: 22px;-moz-border-radius: 22px;border-radius: 22px;background:{bc};box-shadow:0 0 3px rgba(0,0,0,.3);color:{bt};white-space: nowrap;font:11px\/12px Tahoma, Geneva, sans-serif!important;"]
,[[1088,".pluso-counter"],"position:relative;padding-right:18px;"]
,[[1088,".pluso-counter b"],"top:-6px;left:18px;"]
,[[1344,".pluso-counter b"],"top:-16px;left:18px;"]
,[[1088,".pluso-counter b:after"],"position: absolute;top: 5px;left: -6px;z-index: 0;display: block;width: 0;border-width: 4px 8px 4px 0;border-style: solid;border-color: transparent {bc};content: '';"]
,[[576,".pluso-counter"],"position:relative;display:block;margin-top:20px;width:100%;text-align:center;"]
,[[576,".pluso-counter:after"],"position: absolute;top: -5px;left: 50%;margin-left:-4px;z-index: 10;display: block;width: 0;border-width: 0 4px 8px;border-style: solid;border-color: {bc} transparent;content: '';"]
,[[16,".pluso-counter b"],"position:relative;padding:6px 8px;-webkit-border-radius: 30px;-moz-border-radius: 22px;border-radius: 30px;background:{bc};box-shadow:0 0 3px rgba(0,0,0,.3);color:{bt};white-space: nowrap;font:12px\/14px Tahoma, Geneva, sans-serif!important;"]
,[[1040,".pluso-counter"],"position:relative;padding-right:18px;"]
,[[1040,".pluso-counter b"],"top:-10px;left:18px;"]
,[[1296,".pluso-counter b"],"top:-27px;left:23px;"]
,[[1040,".pluso-counter b:after"],"position: absolute;top: 9px;left: -6px;z-index: 0;display: block;width: 0;border-width: 4px 8px 4px 0;border-style: solid;border-color: transparent {bc};content: '';"]
,[[528,".pluso-counter"],"position:relative;display:block;margin-top:20px;width:100%;text-align:center;"]
,[[528,".pluso-counter:after"],"position: absolute;top: -10px;left: 50%;margin-left:-4px;z-index: 10;display: block;width: 0;border-width: 0 4px 8px;border-style: solid;border-color: {bc} transparent;content: '';"]
,[[32,".pluso-counter b"],"position:relative;padding:8px 12px;-webkit-border-radius: 22px;-moz-border-radius: 22px;border-radius: 122px;background:{bc};box-shadow:0 0 3px rgba(0,0,0,.3);color:{bt};white-space:nowrap;font:16px\/40px Tahoma, Geneva, sans-serif!important;"]
,[[1056,".pluso-counter"],"position:relative;padding-right:28px;"]
,[[1056,".pluso-counter b"],"top:-14px;left:28px;"]
,[[1312,".pluso-counter b"],"top:-35px;left:28px;"]
,[[1056,".pluso-counter b:after"],"position: absolute;top: 13px;left: -8px;z-index: 0;display: block;width: 0;border-width: 5px 9px 5px 0;border-style: solid;border-color: transparent {bc};content: '';"]
,[[544,".pluso-counter"],"position:relative;display:block;margin-top:30px;width:100%;text-align:center;"]
,[[544,".pluso-counter:after"],"position: absolute;top: -8px;left: 50%;margin-left:-4px;z-index: 10;display: block;width: 0;border-width: 0 5px 11px;border-style: solid;border-color: {bc} transparent;content: '';"]
,[[128,"br"]," display:none; "]
,[[4,".pluso-counter"]," display:none; "]
,[["",".pluso-box"],"position:absolute;border:4px solid #eaebea;width:310px;height:225px;overflow:hidden;z-index: 777;background:#f2f2f2;font:normal normal 12px\/25px Tahoma, Geneva, sans-serif;box-shadow:0 4px 10px rgba(0, 0, 0, 0.4);text-align:left;-webkit-border-radius:14px;-moz-border-radius:14px;border-radius:14px;"]
,[["",".pluso-box a b"],"width:20px;height:20px;position:absolute;left:0;top:2px;"]
,[["",".pluso-box a:visited,.pluso-box a:hover,.pluso-box a"],"font:normal normal 12px\/25px Tahoma, Geneva, sans-serif;color:#7f7f7f;text-decoration:none;white-space:nowrap;padding:0 0 0 25px;margin:0 0 0 5px;border:0;position:relative;width:115px;float:left;"]
,[["",".pluso-box .pluso-list"],"background:#ffffff;border-radius:14px;width:100%;height:200px;overflow:auto;position:absolute;left:0;top:25px;"]
,[["",".pluso-box a.pluso-logo"],"background:url({i}\/i\/logo-mini.png) 0 5px no-repeat;width:66px;height:19px;border:0;text-indent:-600em;padding:0 0 0 12px;margin:0 0 0 9px;"]
,[["",".pluso-box a.pluso-go"],"color:#4c4c4c;text-decoration:underline;padding-left:0;"]
,[["",".pluso-box a.pluso-close,.pluso-box a.pluso-close:hover,.pluso-box a.pluso-close:visited"],"float:right;width:20px;text-align:center;font-size:12px;line-height:20px;width:20px;margin:1px 1px 0 0;padding:0;font-weight:bold;color:#4c4c4c;text-decoration:none;background:#ffffff;border-radius:15px;border:1px solid #eaebea;"]
,[["",".pluso-box a.pluso-close:hover"],"background:#7f7f7f;color:#ffffff;border-color:transparent"]];

  pluso.tree = [
    ['horizontal','vertical',
     'multiline','line',
     'small','big','medium',
     'counter','nocounter',
     'round','square'
    ],
    {
     horizontal:'vertical',
     multiline:'line',
     small:['big','medium'],
     counter:'nocounter',
     round:'square',

     vertical:'horizontal',
     line:'multiline',
     big:['small','medium'],
     nocounter:'counter',
     square:'round',

     medium:['small','big']
    },
    [
     ['round','square'],
     ['small','big','medium']
    ]
  ];

  // ordered list of services, titles, image offsets in sprite and id's
  pluso.titles = [
  	['vkontakte','ВКонтакте',5,3],
  	['odnoklassniki','Одноклассники',4,4],
  	['facebook','Facebook',1,1],
  	['twitter','Twitter',2,2],
  	['google','Google+',7,5],
  	['moimir','Мой Мир@Mail.Ru',8,7],
  	['pinterest','Pinterest',6,17],
  	['livejournal','LiveJournal',9,6],
  	['tumblr','Tumblr',3,22],
  	['liveinternet','LiveInternet',10,8],
  	['springpad','Springpad',11,19],
  	['stumbleupon','StumbleUpon',12,20],
  	['myspace','mySpace',13,15],
  	['formspring','Formspring.me',14,13],
  	['blogger','Blogger',15,9],
  	['digg','Digg',16,11],
  	['surfingbird','Surfingbird',17,21],
  	['bobrdobr','БобрДобр',18,24],
  	['readability','Readability',19,18],
  	['instapaper','Instapaper',20,14],
  	['evernote','Evernote',21,12],
  	['delicious','Delicious',26,10],
  	['vkrugu','В Кругу Друзей',25,25],
  	['pinme','Pinme',27,16],
  	['yandex','Я.ру',28,23],
  	['yazakladki','Яндекс.Закладки',29,29],
  	['moikrug','МойКруг',30,30],
  	['googlebookmark','Google закладки',31,31],
  	['yahoo','Yahoo закладки',32,32],
  	['moemesto','МоёМесто',33,33],
  	['memori','Memori.ru',34,34],
  	['juick','Juick',36,35],
  	['linkedin','LinkedIn',37,36],
  	['webdiscover','WebDiscover',39,37],
  	['bookmark','В закладки',22,26],
  	['email','Отправить на email',23,27],
  	['print','Печатать',24,28]
  ];


  // services names and positions for pluso.titles
  pluso.services = false;

  // loaded themes indicator
  pluso.sets = {}

  // counters for all button sets
  pluso.counter = {}
  pluso.counters = {}

  pluso.offsets = {
    'small':21,
    'medium':31,
    'big':42
  };


  pluso.tabbed = [
    'livejournal',
    'liveinternet',
    'stumbleupon',
    'bobrdobr',
    'evernote',
    'instapaper',
    'digg'
  ];

  pluso.defaults={
    options:{
      horizontal:1,
      line:1,
      small:1,
      counter:1,
      round:1,
      theme:'04'
    },

    services: [],

    params: {
      background:'#eaeaea',
      baloon:'#eaeaeb',
      text:'#707070',

      url:w.location.href.split('#')[0],
      title:d.title,
      image:'',
      description:'',
      user:0,
      lang:'ru'
    }
  };


  pluso.html = function(elem, debug)
  {
      if (elem.pluso) return false;
      if (elem.className.split(' ').indexOf('pluso-skip')>-1) return false;

      var ep=elem.pluso=cloned(pluso.defaults);

      function unset(key)
      {
        if(!key) return;
        if (arrayed(key))
        {
          for (var i=0;i<key.length;i++) unset(key[i]);
        }
        else
        {
          delete ep.options[key];
        }
      }

      var options = elem.getAttribute("data-options");

      if (options) options.split(',').map( function(a){
        k=a.split('=');

        //old style
        if(arrayed(k) && (k.length>1))
        {
          if (k[1]=='0')
          {
            var i=pluso.tree[1][k[0]];
            if(arrayed(i)) i=i[0];

            k=[i, 1];
          }
        }
        else
        {
          k=[k[0], 1];
        }

        unset(pluso.tree[1][k[0]]);
        return ep.options[k[0]]=k[1];
      });

      var services = elem.getAttribute("data-services");
      if (services) ep.services=services.split(',');

      iterate(ep.params, function(key, obj){
           var value = elem.getAttribute("data-"+key);
           if (value) obj[key]=value;
      });


      if (ep.params.url.split('://').length<2) ep.params.url=prot + '://' + ep.params.url;
      if( (ep.params.url.indexOf('#') == -1) && (ep.params.url.split('/').length<4) ) ep.params.url+='/';

      var opt=[], uniq=[], o=ep.options, j, num;

      //calculate option mask and uniq number
      pluso.tree[0].map(function(key){
        j=(typeof o[key]!='undefined' && o[key]=='1')?'1':'0';
        if (j>0) opt.push(key);

        uniq.push(j);
      });

      uniq=uniq.join('');
      num=parseInt(uniq,2);

      uniq='pluso-'+uniq+'-'+ o.theme;

      opt.push('t'+o.theme);

      var reps = {'u':u, 'i':u, 'bb':ep.params.background, 'bc':ep.params.baloon, 'bt':ep.params.text};

      var html=['<div class="'+ uniq + (debug?' ' + opt.join(' '):'') +'">'], css=[], p, m;

      var replacer = function(p){

        return p.replace(/\{(\w+)\}/g, function(s, key) {
          return reps[key] || s;
        })
      }

      // create css
      if (typeof pluso.sets[uniq]=='undefined')
      {
        for(var i=0;i<pluso.css.length;i++)
        {
          p = pluso.css[i];

          if ( ((p[0][0]=='') && !pluso.services) || ((num & p[0][0]) == p[0][0]) )
          {
            css.push((p[0][0]==''?'':'.'+uniq+' ')+p[0][1]+'{'+replacer(p[1])+'}');
          }
        }

        // service image for current combination of styles
        p=[];
        for(var i=0;i<pluso.tree[2].length;i++)
        {
          for (var j=0;j<pluso.tree[2][i].length;j++)
          {
            if (o[pluso.tree[2][i][j]] && (o[pluso.tree[2][i][j]]!=0))
            {
              p.push(pluso.tree[2][i][j]);
              continue;
            }
          }
        }
        p.push(o['theme']);

        css.push('.'+uniq+' .pluso-wrap a{ background-image:url('+u+'/i/'+p.join('/')+'.png) }');
      }

      // services styles for popup box
      if (!pluso.services)
      {
        pluso.services={};
        css.push('.pluso-box a b{ background-image:url('+u+'/i/round/small/04.png) }');

        for(var i=0,l=pluso.titles.length;i<l;i++)
        {
          p = pluso.titles[i];
          pluso.services[p[0]]=i;
          css.push('.pluso-box a.pluso-'+p[0]+' b{ background-position: -'+((p[2]-1)*pluso.offsets.small)+'px 0}');
        }
      }


      var x=pluso.offsets[o['small']==1?'small':(o['medium']==1?'medium':'big')];

      html.push('<span class="pluso-wrap" style="background:'+ep.params.background+'">');

      for(var i=0,l=ep.services.length,q=l/2;i<l;i++)
      if (typeof pluso.services[ep.services[i]]!='undefined')
      {
         p = pluso.titles[pluso.services[ep.services[i]]];
         pt = lang(elem, p[0], p[1]);

         html.push('<a href="'+ep.params.url+'" title="'+pt+'" class="pluso-'+p[0]+'"'+(p[0]=='bookmark'?' rel="sidebar"':'')+'></a>');

         // service image offset
         if(!pluso.sets[uniq] || (pluso.sets[uniq].indexOf(p[0]<0)) )
         {
            css.push('.'+uniq+' .pluso-wrap a.pluso-'+p[0]+'{ background-position: -'+((p[2]-1)*x)+'px 0}');

            if (!pluso.sets[uniq]) pluso.sets[uniq]=[];
            pluso.sets[uniq].push(p[0]);
         }

         if (o.horizontal>0 && o.multiline>0 && (o.multiline!=2) && (i+1>=q))
         {
           o.multiline=2;
		   html.push('<br>');
		 }
      }

      html.push('<a href="'+prot+'://pluso.ru/" class="pluso-more"'+
               ((o.horizontal>0 && o.multiline>0 && (ep.services.length%2!=0))?' style="margin-left:'+(x+5)+'px; *left:'+(x+5)+'px"':'')+
               '></a>');
      html.push('</span>');

      if (o.counter>0)
      html.push('<span class="pluso-counter"><b>'+(pluso.counter[ep.params.url] || '0')+'</b></span>');

      html.push('</div>');


      if (!pluso.sets[uniq]) pluso.sets[uniq] = [];

      return {'html':html.join(''), 'css':css.join('')};
  }

  pluso.styles = function(r)
  {
    var ret=[];

    ['small','big','medium'].map(function(sze)
    {
      ['round','square'].map(function(frm)
      {
          for (var j=1;j<14;j++)
          {
            var thm=((j<10)?'0':'')+j;

            ret.push('.pluso .'+sze+'.'+frm+'.t'+thm+' .pluso-wrap a{ background-image:url('+u+'/i/'+([frm,sze,thm].join('/'))+'.png) }');
            for(var i=0,l=pluso.titles.length;i<l;i++)
            {
              p = pluso.titles[i];
              ret.push('.pluso .'+sze+'.'+frm+'.t'+thm+' .pluso-wrap a.pluso-'+p[0]+'{ background-position: -'+((p[2]-1)*pluso.offsets[sze])+'px 0}');
            }
          };
      });
    });

    ret=ret.join("");

    return r?ret:styled(ret);
  }


  pluso.click = function(elem, menu)
  {
    return function(e)
      {
        if (!e) var e=window.event;
        var t=(e.target||e.srcElement);
        if(t.tagName=='B') t=t.parentNode;

        if(t.tagName=='A')
        switch (t.className)
        {
          case 'pluso-more':
            pluso.more(pointed(e), elem);
          break;
          case 'pluso-promo':
          case 'pluso-logo':
          case 'pluso-go':
            pluso.process(t.className.substring(6), elem);
            return true;
          break;
          case 'pluso-close':
            elem.box.style.display="none";
          break;
          default:
            return pluso.share(t, elem, menu);
          break;
        }

        return false;
      }
  }


  pluso.build=function (elem, debug)
  {
    var tt=pluso.html(elem, debug);
    if(!tt) return false;

    if (tt.css) styled(tt.css);
    elem.innerHTML=tt.html;

    if ( !( (elem.counter=elements('pluso-counter', elem)).length
         && (elem.counter=elem.counter[0][tags]('b')).length
         && (elem.counter=elem.counter[0]))
       )
    {
      elem.counter=d.createElement('b');
    }

    if (!pluso.counter[elem.pluso.params.url]) pluso.counter[elem.pluso.params.url]=0;

    elem.counter.title=pluso.counter[elem.pluso.params.url];
    elem.counter.innerHTML=numk(pluso.counter[elem.pluso.params.url]);

    if (!pluso.counters[elem.pluso.params.url]) pluso.counters[elem.pluso.params.url]=[];
    pluso.counters[elem.pluso.params.url].push(elem.counter);

    elem.onclick=pluso.click(elem, 0);

    var more=elements('pluso-more', elem)[0];

    more.onmouseover=function(e)
    {
      if (!e) var e=window.event;
      var xy=pointed(e);
      more.timer=setTimeout( function(){ pluso.more(xy, elem); }, 500);
    };

    more.onmouseout = function(){
      clearTimeout(more.timer);
    }

    return elem;
  }

  pluso.start = function(el)
  {
    pluso.screenWidth = null;
    pluso.screenHeight = null;

    if (parseInt(navigator.appVersion)>3) {
      pluso.screenWidth = screen.width;
      pluso.screenHeight = screen.height;
    }
    else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
      var jToolkit = java.awt.Toolkit.getDefaultToolkit();
      var jScreenSize = jToolkit.getScreenSize();
      pluso.screenWidth = jScreenSize.width;
      pluso.screenHeight = jScreenSize.height;
    }

    var el = el || elements('pluso');

    for(var ei=0,ll=el.length;ei<ll;ei++)
    {
      if (pluso.build(el[ei])) pluso.process('counter', el[ei], (!pluso.cnt++?'&first=1':''));
    }

  }

  pluso.share_pinterest = function() {
    js('http://assets.pinterest.com/js/pinmarklet.js?r=' + Math.random() * 99999999);
  };

  pluso.share_pinme = function() {
    js('http://st.pinme.ru/js/pinbutton.js?r=' + Math.random() * 99999999);
  };

  pluso.share_readability = function() {
    js('http://www.readability.com/bookmarklet/save.js?r=' + Math.random() * 99999999);
  };

  pluso.share_print = function() {
    window.print();
  };

  pluso.share_bookmark = function(ep) {

    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
    	window.sidebar.addPanel (ep.params.title, ep.params.url, "");
    } else if (typeof window.external == "object" && !window.chrome) {
    	window.external.AddFavorite(ep.params.url, ep.params.title);
    } else prompt('Скопируйте и добавьте эту ссылку в Закладки', ep.params.url);

  };

  pluso.share_email = function(ep) {
    var link = "mailto:?Subject="+ep.params.title+"&body="+encodeURIComponent(ep.params.url)+"%0A";
    window.open(link, 'mailto');
  };

  pluso.params = function(elem)
  {
    return 'u=' + encode(elem.pluso.params.url)
      		+ (pluso.screenWidth && pluso.screenHeight ? '&w=' + pluso.screenWidth + '&h='+ pluso.screenHeight : '')
      		+ '&ref=' + encode(d.referrer)
      		+ (elem.pluso.params.user>0?'&user=' + encode(elem.pluso.params.user):'')
      		+ '&uid=' + uid
      		+ '&k='+pluso.randomString(16);
  }

  pluso.share = function(t, elem, menu)
  {
    var sharer=t.className.substring(6),
        share = pluso["share_"+sharer],
        sharelink = pluso.sharelink(sharer, elem, menu);

    // increment counter for faster feedback without server call
    pluso.counter[elem.pluso.params.url]+=1;

    elem.counter.title=pluso.counter[elem.pluso.params.url];
    elem.counter.innerHTML=numk(pluso.counter[elem.pluso.params.url]);

    if (typeof share == "function")
    {
      js(sharelink);

      if(window.opera && (sharer=='bookmark'))
      {
        t.href = elem.pluso.params.url;
        return true;
      }
      else
      {
        share(elem.pluso);
      }
    }
    else
    {
      if (!window.open(sharelink, sharer, pluso.tabbed.indexOf(sharer)==-1?'toolbar=0,status=0,resizable=1,width=626,height=436':'')) {
      	w.location.href = sharelink;
      }
    }
    return false;
  }

  pluso.more = function(xy, elem)
  {
    if (elem.box){
      var div=elem.box;
    }
    else
    {
      var div = d.createElement("div"), html=[];
      div.className = "pluso-box";

      html.push('<a href="'+u+'/?new" target="_blank" class="pluso-logo">+PLUSO</a>');
      html.push('<a href="'+u+'/?new" target="_blank" class="pluso-go">'+lang(elem, 'get')+'</a>');
      html.push('<a href="#close" title="'+lang(elem, 'close')+'" class="pluso-close">&times;</a>');

      html.push('<div class="pluso-list">');
      for(var i=0,l=pluso.titles.length;i<l;i++)
      {
        p = pluso.titles[i];
        pt = lang(elem, p[0], p[1]);
        html.push('<a href="'+elem.pluso.params.url+'" title="'+pt+'" class="pluso-'+p[0]+'"'+(p[0]=='bookmark'?' rel="sidebar"':'')+'><b></b>'+pt+'</a>');
      }
      var bn=(Math.random()>0.5?'1':'2');
      html.push('<a class="pluso-promo" style="display:block;width:100%;height:200px;margin:0;padding:0;background:url('+u+'/i/promo_'+bn+'.png) center center no-repeat" href="http://'+(bn==1?'chrome':'music')+'.pluso.ru/?new'+(bn==1?'chromeaddon':'music')+'" target="_blank"></a>');
      html.push('</div>');

      div.innerHTML=html.join('');

      div.onmouseover=function(ev)
      {
        if (div.timer) clearTimeout(div.timer);
      }

      div.onmouseout=function(ev)
      {
        var ev=ev || w.event, e = ev.toElement || ev.relatedTarget, t=(ev.target||ev.srcElement);

        if(e && e.tagName && (e.tagName.toUpperCase()=='B')) e=e.parentNode;

        if (!e || e == div || e.parentNode == div || e.parentNode.parentNode == div)
        {
           return false;
        }

        div.timer = setTimeout( function(){ div.style.display="none" }, 777)
      }

      div.onclick = pluso.click(elem, 1);
    }

    if (elem.box && (elem.box.style.display=='block')) return;

    var z=pluso.offsets[elem.pluso.options['small']==1?'small':(elem.pluso.options['medium']==1?'medium':'big')]/2,
        x=xy.pageX-z, y=xy.pageY-z, ws=dimensions();

    if (x<0) x=10;
    else if (x+310>ws.width) x=ws.width-350;

    if (y<0) y=5;
    else if (y+265>ws.height) y=ws.height-265;

    div.style.left=x+'px';
    div.style.top=y+'px';


    if (elem.box)
    {
      elem.box.style.display="block";
    }
    else
    {
      elem.box=div;
      d[tags]("body")[0].appendChild(div);
    }

    pluso.process('menu', elem);
  }


  pluso.sharelink = function(sharer, elem, menu)
  {
    var k = d.getSelection, y = w.getSelection, x = d.selection;
    var s = (y ? y() : (k) ? k() : (x ? x.createRange().text : 0));

	return u+'/process?act=share&'+pluso.params(elem)+
	         '&type=' + encode(sharer) +
	         '&t=' + encode(elem.pluso.params.title) +
	         '&s=' + encode(s||elem.pluso.params.description) +
	         (elem.pluso.params.image?'&img=' + encode(elem.pluso.params.image):'') +
	         (menu?'&menu=1':'');
  };


  // logo, go, menu, counter
  pluso.process = function (action, elem, params)
  {
    js('+process?act='+action+'&'+pluso.params(elem)+(params || ''));
  }

  pluso.setCounter = function (c, url)
  {
    if (!url) url=w.location.href.split('#')[0];

  	pluso.counter[url]=parseInt(c);

    var cnt=pluso.counters[url];
    if (cnt && cnt.length)
    {
      var n = numk(pluso.counter[url]);
      for(var i=0;i<cnt.length; i++)
      {
        cnt[i].title=pluso.counter[url];
        cnt[i].innerHTML = n;
      }
    }

    if (typeof pluso_counter == "function") pluso_counter(c, url);
  };

  pluso.randomString = function(length)
  {
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');

    if (! length) {
    	length = Math.floor(Math.random() * chars.length);
    }

    var str = '';
    for (var i = 0; i < length; i++) {
    	str += chars[Math.floor(Math.random() * chars.length)];
    }
    return str;
  };


  ready(function()
  {
    pluso.start();
    if (typeof pluso_ready == "function") pluso_ready();

    new Image().src = prot + "://counter.yadro.ru/hit;PLUSO?r" + escape(document.referrer) + ((typeof(screen)=="undefined")?"" : ";s"+screen.width+"*"+screen.height+"*" + (screen.colorDepth?screen.colorDepth:screen.pixelDepth)) + ";u"+escape(document.URL) + ";h"+escape(document.title.substring(0,80)) + ";1" + pluso.randomString(5);
  });


})(window, document);
